2026-09-20 · linux, class-notes
When you type a command, something has to read it, work out what you mean and ask the operating system to do it. That something is the shell: a program whose whole job is to take keyboard commands and pass them to…
Class notes · William Shotts, The Linux Command Line · Chapter 1
Quick reference: the short version of this chapter is the Chapter 1 cheat sheet.
By the end of these notes you should be able to:
When you type a command, something has to read it, work out what you mean and ask the operating system to do it. That something is the shell: a program whose whole job is to take keyboard commands and pass them to the OS to carry out.
Almost every Linux distribution uses Bash as its default shell. The name stands for "Bourne Again SHell" — an improved replacement for sh, the original Unix shell written by Steve Bourne. Other shells exist (zsh is the default on macOS, and fish is popular), but Bash is the one you'll meet on servers, in scripts and in security tools.
Two pieces of software are working when you open a command line, and it's worth keeping them separate in your head:
Piece
Job
Examples
Terminal emulator
A graphical window that shows text and sends your keystrokes on
GNOME Terminal, Konsole, xterm, Windows Terminal
Shell
Interprets what you type and runs the commands
bash, zsh, sh, fish
+-------------------- Terminal emulator (a window) --------------------+ | | | You type ---> SHELL (bash) ---> Linux kernel ---> hardware | | ^ | | Output <----------+ (results shown in the window) | | | +----------------------------------------------------------------------+The "emulator" part of the name is historical. Real terminals were once physical devices — a screen and keyboard wired to a distant computer. Today a window on your desktop pretends to be one.
Note: a terminal emulator is not the shell. You can run a different shell inside the same terminal window: type zsh or sh to start one, and exit to come back to Bash.
Check which shell you're using:
echo $SHELL \
echo $0 \
When the shell is ready for a command it shows a prompt. The default Bash prompt on most distributions looks like this:
andrew@linuxbox:~$ \____/ \______/ | | | | | +-- $ = normal user \
| | +----- current directory (~ = your home directory) | +----------- hostname (the machine's name) +------------------- usernameThe exact format varies by distribution and can be customised (Shotts covers this later in the book). The two things to read every time are where you are and who you are.
Last character
Meaning
Risk
$
You're a normal user
Mistakes are limited to your own files
#
You're the superuser (root)
Every command runs with full power over the whole system
Prompt
Who
Where
andrew@linuxbox:~$
andrew, normal user
andrew's home directory
andrew@linuxbox:/etc$
andrew, normal user
/etc
root@web01:/var/log#
root — the superuser
/var/log on the machine web01
[andrew@rhel9 ~]$
andrew, normal user
home — Red Hat-style brackets
The third one deserves care: you're root on what sounds like a web server. Slow down before pressing Enter.
In the real world: during an investigation or a pentest, the prompt is the first clue to what you have. Landing on a \
Type random characters and press Enter:
$ kaekfjaeifj bash: kaekfjaeifj: command not foundNothing breaks. The shell tells you it couldn't find a command by that name and gives you the prompt back. Learning to read error messages calmly — rather than guessing — is one of the most useful habits you can build.
Bash remembers what you've typed. By default it keeps the last 1,000 commands in memory (the HISTSIZE setting), and saves them to ~/.bash_history when the shell exits.
Key or command
Does
Up arrow
Previous command
Down arrow
Next command
history
List remembered commands, numbered
history 10
Show the last 10
The history file can be larger than the in-memory list, depending on the distribution's settings.
Key
Does
Left / right arrows
Move the cursor along the line to edit it
Home / End
Jump to the start / end of the line
Backspace / Delete
Remove characters
Enter
Run the line, wherever the cursor is
You don't need to move to the end of the line before pressing Enter — the whole line runs.
It feels slower than retyping for a short command, but it's much faster for long ones, and it avoids introducing new typos.
These are harmless, read-only commands — good for getting a feel for how commands and their output look.
Command
Shows
date
The current date and time
cal
A calendar for the current month
df
Free space on mounted file systems (disk free)
free
Memory and swap use
exit
Ends the session and closes the terminal
cal comes from a separate package on some minimal installs. If it's missing, it's often provided by ncal or util-linux depending on the distribution.
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 98G 41G 52G 45% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/sda1 511M 6.1M 505M 2% /boot/efi- -h means "human-readable": sizes in K, M and G rather than 1K blocks.
$ free -h total used free shared buff/cache available Mem: 7.7Gi 2.1Gi 3.0Gi 210Mi 2.6Gi 5.2Gi Swap: 2.0Gi 0B 2.0Gi- Look at available, not free. Linux uses spare RAM for disk cache (buff/cache) and gives it back when programs need it. Low "free" memory is normal and healthy; low "available" memory is a problem.
A colleague says a Linux server "feels slow". Before anything else, two read-only commands give a first picture:
Theory: disk space. The next step (covered in later chapters) is finding what filled it — very often a runaway log in /var/log.
The X Window System — the graphical layer many Linux desktops have used — offers a fast copy-and-paste method that surprises Windows users:
Action
How
Copy
Just select text with the left mouse button
Paste
Click the middle mouse button (or press the scroll wheel)
This "primary selection" is separate from the normal clipboard.
Caution: never paste commands from a website straight into a terminal without reading them. What you see on a page and what lands on your clipboard can differ, and a pasted line that ends in a newline runs immediately.
Even with a desktop running, Linux keeps several full-screen text virtual consoles available:
Keys
Does
Ctrl+Alt+F1 to F6
Switch to a text console (which numbers are used varies by distribution)
Alt+F1 to F6
Move between consoles once you're in one
Return to the desktop
Usually Ctrl+Alt+F1, F2 or F7, depending on the distribution
Why this matters: if the graphical desktop freezes, a virtual console often still works. You can log in there and fix the problem (for example, stop a misbehaving program) without rebooting.
Method
Does
exit
Ends the shell; the terminal window closes
Ctrl+D at an empty prompt
Sends "end of input" — same effect as exit
Closing the window
Also ends it, but any running command is killed
Term
Definition
Shell
A program that reads typed commands and passes them to the OS to run
Bash
Bourne Again SHell — the standard Linux shell
sh
The original Unix shell, by Steve Bourne
Terminal emulator
A graphical program that provides a window for a shell
Command line interface (CLI)
Controlling a computer by typing commands
Prompt
Text the shell shows when it's ready for input
Home directory
Your personal directory, shown as ~
Superuser / root
The all-powerful administrative account
Command history
Previously entered commands the shell remembers
~/.bash_history
The file where Bash saves command history
df
Reports free and used space on file systems
free
Reports memory and swap usage
Swap
Disk space used as overflow for RAM
Mount point
The directory where a file system appears in the tree
Primary selection
X Window copy buffer: select to copy, middle-click to paste
Interrupt (Ctrl+C)
A signal that stops the running command
Virtual console
A full-screen text login, reached with Ctrl+Alt+F-keys
End of input (Ctrl+D)
Tells the shell there's no more input; ends the session at an empty prompt